Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Incorrect display of "Reply in Direct Message" in MessageAction #17968

Merged
merged 4 commits into from
Feb 18, 2021

Conversation

abrom
Copy link
Contributor

@abrom abrom commented Jun 19, 2020

Proposed changes

Check that we either already have a DM room started with the message user or that we have the create-d permission to start one, otherwise hiding the reply in DM menu option.

Issue(s)

Currently if a user does not have the create-d permission and does not already have a DM started with a user, the "Reply in Direct Message" context menu option is still displayed for messages even though clicking it will show the user a "User not found - Invalid room" page and "Not allowed [error-not-allowed]" toast message.

Screenshots

Screen Shot 2020-06-19 at 4 46 59 pm

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Hotfix (a major bugfix that has to be merged asap)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Changelog

[FIX] Incorrect display of "Reply in Direct Message" in MessageAction

Further comments

Note I've left the tests in a separate commit for now as they weren't super simple due to some of the setup required to test this. I tried to find other examples of tests that did similar things but didn't really find anything suitable. Would be good to get some feedback as to if there would be a better way to do the setup?

abrom added 2 commits June 20, 2020 03:21
Check that we either already have a DM room started with the message user or
that we have the `create-d` permission to start one, otherwise hiding the reply
in DM menu option.

Currently if a user does not have the `create-d` permission and does not already
have a DM started with a user, the "Reply in Direct Message" context menu is still
displayed for messages even though clicking it will show the user a "User not
found - Invalid room" page and "Not allowed [error-not-allowed]" toast message.
@abrom abrom marked this pull request as ready for review June 19, 2020 18:21
@sampaiodiego sampaiodiego requested a review from ggazzo July 27, 2020 15:07
Copy link
Contributor

@MartinSchoeler MartinSchoeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! So far this PR is looking good, I've mentioned some improvements that can be done in it. Thanks!


// Check if we already have a DM started with the message user (not ourselves) or we can start one
const dmRoom = Rooms.findOne({ _id: [u._id, msg.u._id].sort().join('') });
const canAccessDM = dmRoom && Subscriptions.findOne({ rid: dmRoom._id, 'u._id': u._id });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe before doing multiple findOnes, we can check if the user lack the permission, so we can avoid calling these methods when we don't need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting something like this?

// Don't show reply option if we're messaging someone else and we don't have
// permission to start a new DM with them
if (u._id !== msg.u._id && !hasPermission('create-d')) {
  const dmRoom = Rooms.findOne({ _id: [u._id, msg.u._id].sort().join('') });
  if (!dmRoom || !Subscriptions.findOne({ rid: dmRoom._id, 'u._id': u._id })) {
    return false;
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinSchoeler are you suggesting something like ☝️ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinSchoeler thoughts RE my suggested fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @MartinSchoeler still awaiting your feedback.

@ggazzo ggazzo added this to the 3.10.0 milestone Dec 3, 2020
Copy link
Contributor

@MartinSchoeler MartinSchoeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those changes are good! Sorry for the delay, I had some issues with my GH notifications

@abrom
Copy link
Contributor Author

abrom commented Feb 15, 2021

What's needed to get this moving along @MartinSchoeler ?

@ggazzo ggazzo merged commit 3a5e28c into RocketChat:develop Feb 18, 2021
@sampaiodiego sampaiodiego mentioned this pull request Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants